<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
          name='viewport'/>

    <title>教务综合管理系统</title>

    <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/asserts/css/demo.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/asserts/css/ready.css}">

    <style>
        table tr{
            height: 50px;
        }

        table td {
            text-align: center;
        }

        table th {
            text-align: center;
        }
    </style>
</head>
<body>

<div class="wrapper">

    <!--    引入公共页面 public-index。html 的模块-->
    <div th:replace="teacher/public-teacher-index :: header"></div>
    <div th:replace="teacher/public-teacher-index :: left"></div>

    <div class="main-panel">
        <div class="content">
            <div class="row">
                <!--<div class="col-md-1"></div>-->
                <div class="col-md-12">
                    <div class="card" style="width:100%;height:100%;">
                        <div class="card-header">
                            <h5 class="card-title">申请详情</h5>
                        </div>
                        <div class="card-body">
                            <div class="btn-group" role="group" aria-label="...">
                                <button type="button" class="btn btn-default" id="all">全部</button>
                                <button type="button" class="btn btn-default" id="submitted">已提交</button>
                                <button type="button" class="btn btn-default" id="success">已通过</button>
                                <button type="button" class="btn btn-default" id="failed">未通过</button>
                            </div>
                            <div class="table-responsive" style="margin-top: 20px">
                                <table class="table table-bordered table-hover" id="condition_work_table">
                                    <thead style="background-color: #f9f9f9">
                                    <tr>
                                        <th width="50">序号</th>
                                        <th>类型</th>
                                        <th>时间</th>
                                        <th>内容</th>
                                        <th>地址</th>
                                        <th>人数</th>
                                        <th>申请时间</th>
                                        <th>状态</th>
                                        <th>审核人</th>
                                        <th>审核时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    </tbody>
                                </table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/webjars/jquery/1.9.1/jquery.js}"></script>
<script type="text/javascript" th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/ready.min.js}"></script>
<script type="text/javascript">
    $(function () {
        fun()
    })

    //获取教师申请信息
    function fun() {
        $.ajax({
            url: "select_work_all",
            type: "get",
            success: function (result) {
                console.log(result);
                build_work_table(result)
            }
        })
    }

    function build_work_table(result) {
        $("#condition_work_table tbody").empty()
        var work = result.extend.workinfo
        $.each(work, function (index, item) {
            var id = $("<td></td>").append(item.id);
            var content = $("<td></td>").append(item.workcontent);
            var time = $("<td></td>").append(timestampToTime(item.beginDate) + " - " + timestampToTime(item.endDate))
            var typeName = $("<td></td>").append(item.typeName);
            var location = $("<td></td>").append(item.location);
            var number = $("<td></td>").append(item.member);
            var sumbitdate = $("<td></td>").append(timestampToTime(item.sumbitdate));
            if (item.appovalflag == 0) {
                var appovalflag = $("<td></td>").append("待审核");
            } else if (item.appovalflag == 1) {
                var appovalflag = $("<td></td>").append("通过");
            } else {
                var appovalflag = $("<td></td>").append("未通过");
            }
            if(item.appovalflag == 1 || item.appovalflag == 2){
                var appovaldate = $("<td></td>").append(timestampToTime(item.appovaldate));
            }else{
                var appovaldate = $("<td></td>");
            }

            var idSubadmin = $("<td></td>").append(item.idSubadmin);
            if (item.appovalflag != 1) {
                var delBtn = $("<button></button>").addClass("btn btn-danger btn-sm delete_btn")
                    .append($("<span></span>").addClass("glyphicon glyphicon-trash")).append("删除");
                delBtn.attr("del-id", item.id);
                var btnTd = $("<td></td>").append(delBtn);
            }
            $("<tr></tr>")
                .append(id)
                .append(typeName)
                .append(time)
                .append(content)
                .append(location)
                .append(number)
                .append(sumbitdate)
                .append(appovalflag)
                .append(idSubadmin)
                .append(appovaldate)
                .append(btnTd)
                .appendTo("#condition_work_table tbody");

        })
    }

    $(document).on("click", ".delete_btn", function () {
        var id = $(this).attr("del-id")
        $.ajax({
            url:"delete_work?id="+id,
            type:"post",
            success:function () {
                alert("删除成功")
                window.location.reload()

            },
            error:function () {
                alert("删除失败")
            }
        })
    })

    $("#all").click(function () {
        fun()
    })

    $("#submitted").click(function () {
        $.ajax({
            url: "select_work_submitted",
            type: "get",
            success: function (result) {
                build_work_table(result)
            }
        })
    })

    $("#success").click(function () {
        $.ajax({
            url: "select_work_success",
            type: "get",
            success: function (result) {
                build_work_table(result)
            }
        })
    })

    $("#failed").click(function () {
        $.ajax({
            url: "select_work_failed",
            type: "get",
            success: function (result) {
                build_work_table(result)
            }
        })
    })

    function timestampToTime(timestamp) {
        var date = new Date(timestamp);
// 时间戳为10位需 * 1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '/';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
        D = (date.getDate() < 10 ? '0' + (date.getDate()) : (date.getDate()));
        return Y + M + D;
    }
</script>
</html>